package com.foreveross.bsl.mam.device.web;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.foreveross.bsl.mam.device.application.DeviceSceneApplication;
import com.foreveross.bsl.mam.device.application.vo.DeviceSceneVO;
import com.foreveross.bsl.web.BaseController;


/**
 * 设备场景操作类
 * @author tanzhixiong
 * @2013-6-22 @下午3:01:42
 */
@Controller
@RequestMapping("/mam/devicescence")
public class DeviceScenceController  extends BaseController{
	
	@Inject
	private DeviceSceneApplication deviceScenceApplication;
	
	
	@ResponseBody
	@RequestMapping("/add")
	public Map<String, String> add(DeviceSceneVO deviceSceneVO) {
		Map<String, String> result = new HashMap<String, String>();
		deviceSceneVO.setCreateTime(new Date());
		deviceSceneVO.setCode("LOCK_WIPE");
		deviceSceneVO.setDescribe("使指定的设备进行锁屏");
		deviceSceneVO.setModified_time(new Date());
		deviceSceneVO.setName("锁屏");
		deviceSceneVO.setState(1);
		deviceScenceApplication.saveEntity(deviceSceneVO);
		result.put("result", "success");
		return result;
	}
	
	
	@RequestMapping("/showdevicescence")
	public String showDeviceScence(Model model) {
		List<DeviceSceneVO> deviceScenevo;
		deviceScenevo = deviceScenceApplication.findAll();
		model.addAttribute("lists", deviceScenevo);
		
		return "device/deviceScence-list";
	}
	
	
	@ResponseBody
	@RequestMapping("/update")
	public Map<String, String> update() {
		Map<String, String> result = new HashMap<String, String>();
		List<DeviceSceneVO> list =deviceScenceApplication.findAll();
		DeviceSceneVO deviceSceneVO = new DeviceSceneVO();
		deviceSceneVO.setCreateTime(new Date());
		deviceSceneVO.setCode("LOCK_WIPE");
		deviceSceneVO.setDescribe("使指定的设备进行锁屏操作");
		deviceSceneVO.setModified_time(new Date());
		deviceSceneVO.setName("锁屏");
		deviceSceneVO.setState(1);		
		deviceScenceApplication.updateEntity(list.get(1).getId(), deviceSceneVO);
		result.put("result", "success");
		return result;
	}

	@ResponseBody
	@RequestMapping("/deleteAll")
	public Map<String, Object> deleteAll() {
		Map<String, Object> result = new HashMap<String, Object>();
//		deviceScenceApplication.deleteAll();
		result.put("result", "success");
		return result;
	}


	protected String getModuleMenuName() {
		// TODO Auto-generated method stub
		return "设备管理";
	}
	
	
	
	
	

}
